<style>
<!--

.dateDd span.error {
    position: absolute !important;
    left: 260px;
}
-->
</style>
<div class="pageContent">
    <form method="post" action="${rc.getContextPath()}/manage/equipmentScheduledTime/saveScheduledTime" class="pageForm required-validate" onsubmit="return tsubmit(this);">
        <div class="pageFormContent">
            <input type="hidden" name="navTabId" value="${navTabId!''}"> <input type="hidden" name="id" value="<#if (scheduledTime.id)??>${scheduledTime.id!''}</#if>">
            <fieldset class="dataset">
                <dl>
                    <dt><@label key="equipmentCode.C,colon">设备编号：</@label></dt>
                    <dd  class="dateDd">
                        <input class="required look" id="equipmentLookup.equipmentCode" name="equipmentCode" type="text" postField="equipmentCode" suggestFields="equipmentCode,equipmentText" suggestUrl="${rc.getContextPath()}/manage/equipment/equipmentSuggest" value="<#if (scheduledTime.equipmentCode)??>${scheduledTime.equipmentCode!''}</#if>" lookupGroup="equipmentLookup" warn="<@label key='equipmentCode.C,doesNotExist.C'>设备编号不存在</@label>" remote="${rc.getContextPath()}/manage/equipment/validateEquipmentCodeForSelect" /> <a class="btnLook" href="${rc.getContextPath()}/manage/equipment/equipmentLookUp" rel="equipmentLookup_dialog" width="700" height="450" lookupGroup="equipmentLookup"></a>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key='equipmentText.C,colon'>设备描述：</@label></dt>
                    <dd>
                        <input id="equipmentLookup.equipmentText" value="<#if (scheduledTime.equipmentText)??>${scheduledTime.equipmentText!''}</#if>"  readonly size="22" type="text" maxlength="60" name="equipmentText" />
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="theDate.C,colon">作业日期：</@label></dt>
                    <dd class="dateDd">
                        <input type="text" id="theDate" class="required date" readonly="readonly" name="theDate" dateFmt="yyyy-MM-dd" value="<#if (scheduledTime.theDate)??>${scheduledTime.theDate?string("yyyy-MM-dd")}</#if>"/> <a class="inputDateButton" href="javascript:;"><@label key="select.B">选择</@label></a>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="plannedstartDateTime.C,colon">计划开始时间：</@label></dt>
                    <dd class="dateDd">
                        <input id="startDateTime" readonly type="text" class="required date" max_Date="{endDateTime}" name="startDateTime" dateFmt="yyyy-MM-dd HH:mm" value="<#if (scheduledTime.startDateTime)??>${scheduledTime.startDateTime?string("yyyy-MM-dd HH:mm:ss")}</#if>"/> <a class="inputDateButton" href="javascript:;"><@label key="select.B">选择</@label></a>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="plannedendDateTime.C,colon">计划结束时间：</@label></dt>
                    <dd class="dateDd">
                        <input  id="endDateTime" type="text" class="required date" min_Date="{startDateTime}" readonly="readonly" name="endDateTime" dateFmt="yyyy-MM-dd HH:mm" value="<#if (scheduledTime.endDateTime)??>${scheduledTime.endDateTime?string("yyyy-MM-dd HH:mm:ss")}</#if>"/> <a class="inputDateButton" href="javascript:;"><@label key="select.B">选择</@label></a>
                    </dd>
                </dl>
                <dl>
                    <dt><@label key="scheduledTime.C,colon">计划作业时长：</@label></dt>
                    <dd class="dateDd">
                        <input type="text" min="1" id="ss" class="required digits" name="scheduledTime"  maxlength="10" value="<#if (scheduledTime.scheduledTime)??>${scheduledTime.scheduledTime!''}</#if>"/>
                    </dd>
                </dl>
            </fieldset>
        </div>
        <#if (strategy.strategyCode)??> <#assign createInfo=strategy/> <#include "/common/createInfo.html"> </#if>
        <div class="formBar">
            <ul>
                <li><div class="buttonActive">
                        <div class="buttonContent">
                            <button type="submit"><@label key="save.B">保存</@label></button>
                        </div>
                    </div>
                </li>
                <li>
                    <div class="buttonActiveGrey">
                        <div class="buttonContent">
                            <button type="button" class="close"><@label key="cancel.B">取消</@label></button>
                        </div>
                    </div></li>
            </ul>
        </div>
    </form>
</div>

<script type="text/javascript">
$(function(){  
    $("#startDateTime").change(function() {
        calTime();
        });
    $("#endDateTime").change(function() {
        calTime();
        });
});

function calTime()
{
    var start=$("#startDateTime").val();
    var end=$("#endDateTime").val();
    
    if(start.length==0||end.length==0)
    {
        $("#ss").removeAttr("max");
    }
    else
    {
        var dt1 = new Date(Date.parse(start.replace(/-/g, '/ ')));
        var dt2= new Date(Date.parse(end.replace(/-/g, '/ ')));
        var diff = parseInt((dt2.getTime() - dt1.getTime()) / (1000 * 60)); 
        if(diff>0)
        {
            $('#ss').attr("max",diff);
            $('#ss').val(diff);
        }
        else
            {
            $("#ss").removeAttr("max");
            }
    }
}

function tsubmit(t)
{
    var start=$("#startDateTime").val();
    var end=$("#endDateTime").val();
    var date=$("#theDate").val();
    if(date.length!=0&&start.length!=0)
        {
        var dt1 = new Date(Date.parse(start.replace(/-/g, '/ ')));
        var dt2= new Date(Date.parse(date.replace(/-/g, '/ ')));
        var diff=dt1-dt2;
        var towDay=48*60*60*1000;
        if(diff>=towDay||diff<0)
        {
            alertMsg.warn('<@label key="scheduledTimeError.M">计划开始时间只可在作业日期的当天或第二天！</@label>');
            return false;
        }
        }
    if(start.length!=0&&end.length!=0)
    {
        var dt1 = new Date(Date.parse(start.replace(/-/g, '/ ')));
        var dt2= new Date(Date.parse(end.replace(/-/g, '/ ')));
        var diff = parseInt((dt2.getTime() - dt1.getTime()) / (1000 * 60)); 
        if(diff<=0)
        {
              alertMsg.warn('<@label key="planDateTimeError.M">计划结束时间必须大于计划开始时间！</@label>');
              return false;
        }
        if(diff>1440)
            {
              alertMsg.warn('<@label key="scheduledEndTimeError.M">计划结束时间只能在计划开始时间的24小时之内！</@label>');
              return false;
            }
    }
     return validateCallback(t, dialogAjaxDone);
}
</script>